package com.maimao.goods.client.factory;

import com.maimao.core.enums.RespCode;
import com.maimao.core.model.resp.Result;
import com.maimao.goods.client.CouponClient;
import com.maimao.goods.client.ShopClient;
import com.maimao.model.info.Coupon;
import com.maimao.model.info.input.ConfirmCoupon;
import com.maimao.model.order.confirm.CouponSimple;
import com.maimao.model.user.Shop;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @author MaoLin Wang
 * @date 2020/11/30 10:03 下午
 */
@Component
@Slf4j
public class CouponFallBackFactory implements FallbackFactory<CouponClient> {

    @Override
    public CouponClient create(Throwable cause) {
        String errorMsg = cause.getMessage() == null ? "" : cause.getMessage();

        return new CouponClient() {


            @Override
            public Result<Map<Long, Boolean>> couponUserExist(List<Long> couponIds, Long userId) {
                log.error("调用[CouponClient-couponUserExist({},{})]出错 :{}", couponIds, userId, errorMsg);
                return Result.fail(RespCode.FAIL, errorMsg);
            }

            @Override
            public Result<List<CouponSimple>> takeAndQueryUsefulShopCoupon(ConfirmCoupon confirmCoupon) {
                log.error("调用[CouponClient-takeAndQueryUsefulShopCoupon({},{})]出错 :{}", confirmCoupon, errorMsg);
                return Result.fail(RespCode.FAIL, errorMsg);
            }

            @Override
            public Result<List<CouponSimple>> takeAndQuerySysUsefulShopCoupon(ConfirmCoupon confirmCoupon) {
                log.error("调用[CouponClient-takeAndQuerySysUsefulShopCoupon({},{})]出错 :{}", confirmCoupon, errorMsg);
                return Result.fail(RespCode.FAIL, errorMsg);            }
        };
    }
}
